/*------------------------------------------------------------------------------
 * Oracle Certified Professional Java SE 7 Programmer Exams 1Z0-804 and 1Z0-805: 
 * A Comprehensive OCPJP 7 Certification Guide
 * by SG Ganesh and Tushar Sharma
------------------------------------------------------------------------------*/
package chapter11.Threads.dataRaceProblem;

// This class implements Runnable interface 
// Its run method increments the counter three times 
class UseCounter implements Runnable {
	public void increment() {
		// increments the counter and prints the value
		// of the counter shared between threads
		// Comentado para revisar la solución.
		Counter.count++;
		System.out.print(Counter.count + "  ");

		// These two statements perform read and write operations
		// on a variable that is commonly accessed by multiple threads.
		// So, acquire a lock before processing this "critical section"
		// synchronized (this) {
		// Counter.count++;
		// System.out.print(Counter.count + "  ");
		// }
	}

	public void run() {
		increment();
		increment();
		increment();
	}
}